import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义store
export const useUserInfoStore = defineStore(
	'userInfo',
	() => {
		const userInfo = ref()
		
		const setUserInfo = (val) => {
			userInfo.value = val
		}
		
		const clearUserInfo = () => {
			userInfo.value = undefined
		}
		
		return {
			userInfo,
			setUserInfo,
			clearUserInfo,
		}
	},
	
	//持久化
	{
		//配置持久化
		persist: {
			storage: {
				setItem(key, value) {
					uni.setStorageSync(key, value)
				},
				getItem(key) {
					return uni.getStorageSync(key)
				},
			}
		}
	}
)